package com.edmond.jyframe.activity;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.WindowManager;

import com.edmond.jyframe.R;
import com.edmond.jyframe.activity.base.BaseActivity;
import com.edmond.jyframe.fragments.LoginAccountFragment;
import com.edmond.jyframe.fragments.LoginPhoneFragment;
import com.edmond.jyframe.presenter.base.LoginPresenter;
import com.edmond.jyview.widget.JYFragmentPagerAdapter;

import java.util.ArrayList;

/**
 * Created by edmond on 17-4-28.
 */

public class LoginActivity extends BaseActivity<LoginPresenter> {
    private TabLayout tabLayout = null;

    private ViewPager viewPager = null;

    private ArrayList<Fragment> fragments = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //透明状态栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //透明导航栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

        viewPager = (ViewPager) findViewById(R.id.viewpager);
        tabLayout = (TabLayout) findViewById(R.id.tab);

        fragments.add(new LoginAccountFragment());
        fragments.add(new LoginPhoneFragment());

        viewPager.setAdapter(new JYFragmentPagerAdapter(getSupportFragmentManager(),fragments));

        TabLayout.Tab tab1 = tabLayout.newTab();
        TabLayout.Tab tab2 = tabLayout.newTab();

        tab1.setCustomView(R.layout.tab_account);
        tab2.setCustomView(R.layout.tab_phone);

        tabLayout.addTab(tab1);
        tabLayout.addTab(tab2);

        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
        tabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));
    }

    @Override
    public Class[] initModelName() {
        return new Class[0];
    }
}
